在C++中,如何重载"%"啊,谢谢!
来源:百度知道 编辑:UC知道 时间:2024/05/27 06:52:45
我想重载"%":让"50%",表示的意思是50除以100,请问如何实现。
不知道怎么把双目运算符重载为单目运算符。请大虾指教。
不知道的不要回答好不好!
不知道怎么把双目运算符重载为单目运算符。请大虾指教。
不知道的不要回答好不好!
建议使用函数解决。
没有方法把双目运算符重载为单目运算符。
理论上不可行,但是你可以取巧嘛。
float operator %(const float a,const float b=100)
{
return b/100;
}
C++重载不支持参数数目的变化,所以单目变双目不可能,双目变单目要舍弃一个参数;
folat operator %(const folat &num);
float operator %(const folat &num)
{
return num/100;
}
楼主,你可以试试Ruby。
def old?()
@age >= 50.years
end
安逸不不啊?
float operator %(const float a,const float b=100)
{
return a%b;
}
float operator +(const folat &num)
{
return num/100;
}
float operator %(const float & num)
{
return num / 100;
}